import { defHttp } from '@/utils/http/axios';
import { LoginParams, LoginResultModel, GetUserInfoModel, LoginOutParams } from "./model/userModel";

import { ErrorMessageMode } from '#/axios';

enum Api {
  Login = '/login',
  Logout = '/logout',
  GetUserInfo = '/getUserInfo',
  GetPermCode = '/getPermCode',
  RefreshTokenApi = '/update/token',
  findAllUsers = '/user/findAllUsers'
}

/**
 * @description: user login api
 */
export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<LoginResultModel>(
    {
      url: Api.Login,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * @description: getUserInfo
 */
export function getUserInfo() {
  return defHttp.get<GetUserInfoModel>({ url: Api.GetUserInfo, }, { errorMessageMode: 'none' });
}
export function findAllUsers() {
  return defHttp.get<GetUserInfoModel>({ url: Api.findAllUsers, }, { errorMessageMode: 'none' });
}
export function getPermCode() {
  return defHttp.get<string[]>({ url: Api.GetPermCode });
}

export function doLogout(params:LoginOutParams) {
  return defHttp.post({ url: Api.Logout, params });
}
export function RefreshTokenApi(params,mode: ErrorMessageMode = 'modal') {
  return defHttp.post( {
    url: Api.RefreshTokenApi,
    params,
  },
  {
    errorMessageMode: mode,
  },);
}

